﻿using Exceptionless;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Formatting.Json;

namespace _13日志系统;

class Program
{
    static void Main(string[] args)
    {
        ExceptionlessClient.Default.Startup("sWituSY6WFhiHoScC0hmFCn8y76aeVPPM7b3CK91");
        ServiceCollection service = new ServiceCollection();
        service.AddScoped<Test>();
        service.AddLogging(loggerBuilder =>
        {
            //使用自带的Log系统
            // loggerBuilder.AddConsole();
            //使用Nlog
            // loggerBuilder.AddNLog();
            // loggerBuilder.SetMinimumLevel(LogLevel.Warning);
            
            //使用代码配置serilog
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .Enrich.FromLogContext()
                .WriteTo.Console(new JsonFormatter())
                .WriteTo.Exceptionless()
                .CreateLogger();
            loggerBuilder.AddSerilog();
        });
        using (var sp = service.BuildServiceProvider())
        {
            var test = sp.GetRequiredService<Test>();
            test.PrintLog();
        }
    }
   
}

class Test
{ 
    private ILogger<Test> myLog;

    public Test(ILogger<Test> myLog)
    {
        this.myLog = myLog;
    }

    public void PrintLog()
    {
        myLog.LogInformation("this is log information");
        myLog.LogDebug("this is debug information");
        myLog.LogWarning("this is warning information");
        myLog.LogError("this is error information");
        myLog.LogInformation("新增用户{@person}",new {Id = 3,Name = "zack"});
    }
}